package svc

import (
	"UserServer/models"
	"UserServer/rpc/internal/config"
	"fmt"
	"gorm.io/gorm"
)

type ServiceContext struct {
	// Db     models.UserModel  这个是GoZero提供架构，在包models的sqlx
	Config config.Config
	Db     *gorm.DB
}

func NewServiceContext(c config.Config) *ServiceContext {
	//sqlConn := sqlx.NewMysql(c.Mysql.DataSource)
	Db := models.InitGorm(c.Mysql.Dsn(), c.Mysql.LogLevel(), c.Mysql.MaxIdleConn, c.Mysql.MaxOpenConn)

	//Db.Set("gorm:table_options", "ENGINE=InnoDB").AutoMigrate(
	//	&models.User{},
	//)

	fmt.Println("gorm连接成功")
	return &ServiceContext{
		//Db:     models.NewUserModel(sqlConn, c.Cache),
		Config: c,
		Db:     Db,
	}
}
